package sword_to_1;

import java.util.Arrays;

public class LeeCode_45 {
    public static void main(String[] args) {
        System.out.println(minNumber(new int[]{10, 2}));
        System.out.println(minNumber(new int[]{3, 30, 59, 34}));
    }
    private static String minNumber(int[] nums) {
        int n = nums.length;
        String[] sns = new String[n];
        for (int i = 0; i < n; i++) {
            sns[i] = Integer.toString(nums[i]);
        }
        StringBuilder sb = new StringBuilder();
        Arrays.sort(sns, (o1, o2) -> {
            int j = 0;
            while (j < 3){
                if (o1.length() < o2.length()){
                    o1 += o2;
                }else if (o1.length() > o2.length()){
                    o2 += o1;
                }
                int i = 0;
                while (i < o1.length() && i < o2.length()){
                    if (o1.charAt(i) != o2.charAt(i)){
                        return o1.charAt(i) - o2.charAt(i);
                    }
                    i++;
                }
                j++;
            }
            return 1;
        });
        for (String sn : sns) {
            sb.append(sn);
        }
        return sb.toString();
    }
}
